package com.bjpowernode.core.exception;

import com.bjpowernode.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class MyExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        e.printStackTrace();
        return Result.FAIL(e.getMessage());
    }

    @ExceptionHandler(DataIntegrityViolationException.class)
    public Result handleException(DataIntegrityViolationException e) {
        //此处这句只有唯一一个作用->打印出异常，如果没有这句控制台将不会显示出任何异常
        e.printStackTrace();
        return Result.FAIL("外键关联删除失败");
    }
}
